****** Emerging Researchers NSF Project 
****** The Impact of Federal R&D Funding Across the Academy: An Analysis of Early-Career Research Productivity  
****** Data Code: Part 2 - Long Form Figures
****** Built October 2018, Public Version Created June 2019 

********************************************************************************

*** Open Data File for Part 2 (P2)
** Set Directory Path 

********************************************************************************

*** Part 1: Average Variable Generation 

** Generate Averages by Status & Division
* Annual Average Cumulative Publications 	
foreach sample in cemsample {	
bys panel: egen pubA_`sample' = mean(total_article_cum) if award == 1 & `sample' == 1 
bys panel: egen pubH_`sample' = mean(total_article_cum) if award == 0 & `sample' == 1 
forvalue i = 1(1)4 {
bys panel: egen pubA`i'_`sample' = mean(total_article_cum) if award == 1 & div_cd`i' == 1 & `sample' == 1 
bys panel: egen pubH`i'_`sample' = mean(total_article_cum) if award == 0 & div_cd`i' == 1 & `sample' == 1 
}	
}	
* Annual Average 5-Year Citations for Cumulative Publications	
foreach sample in cemsample {	
bys panel: egen citeA_`sample' = mean(total_article_c5yr_cum) if award == 1 & `sample' == 1 
bys panel: egen citeH_`sample' = mean(total_article_c5yr_cum) if award == 0 & `sample' == 1 
forvalue i = 1(1)4 {
bys panel: egen citeA`i'_`sample' = mean(total_article_c5yr_cum) if award == 1 & div_cd`i' == 1 & `sample' == 1 
bys panel: egen citeH`i'_`sample' = mean(total_article_c5yr_cum) if award == 0 & div_cd`i' == 1 & `sample' == 1 
}	
} 
* Annual Average New Publications 	
foreach sample in cemsample {	
bys panel: egen newpubA_`sample' = mean(total_article) if award == 1 & `sample' == 1 
bys panel: egen newpubH_`sample' = mean(total_article) if award == 0 & `sample' == 1 
forvalue i = 1(1)4 {
bys panel: egen newpubA`i'_`sample' = mean(total_article) if award == 1 & div_cd`i' == 1 & `sample' == 1 
bys panel: egen newpubH`i'_`sample' = mean(total_article) if award == 0 & div_cd`i' == 1 & `sample' == 1 
}	
}	
* Annual Average Cumulative Research Outputs 	
foreach sample in cemsample {	
bys panel: egen resA_`sample' = mean(total_rpub_cum) if award == 1 & `sample' == 1 
bys panel: egen resH_`sample' = mean(total_rpub_cum) if award == 0 & `sample' == 1 
forvalue i = 1(1)4 {
bys panel: egen resA`i'_`sample' = mean(total_rpub_cum) if award == 1 & div_cd`i' == 1 & `sample' == 1 
bys panel: egen resH`i'_`sample' = mean(total_rpub_cum) if award == 0 & div_cd`i' == 1 & `sample' == 1 
}	
}	 	 

********************************************************************************

*** Part 2: Descriptive Figures

** Annual Average Cumulative Publications
* By Award Status
foreach sample in cemsample {	
twoway	(connected pubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected pubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))), ///
	ytitle("Number of Total Publications") yscale(range(0 8)) ylabel(0(1)8) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Publications" " ", color(black) size(medsmall)) legend(label(1 "Awardee") label(2 "Honorable Mention")) 
*graph save Graph "$dir/DD_CumPub_`sample'.gph", replace

* By Division & Award Status 
* Enginnering 
twoway	(connected pubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected pubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected pubA1_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected pubH1_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Publications") yscale(range(0 8)) ylabel(0(1)8) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Publications" "Engineering Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "ENG Awardee") label(4 "ENG Honorable Mention")) 
*graph save Graph "$dir/DD_CumPub1_`sample'.gph", replace	

* Life Sciences 
twoway	(connected pubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected pubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected pubA2_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected pubH2_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Publications") yscale(range(0 8)) ylabel(0(1)8) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Publications" "Life Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "LS Awardee") label(4 "LS Honorable Mention")) 
*graph save Graph "$dir/DD_CumPub2_`sample'.gph", replace	

* Math & Physical Sciences 
twoway	(connected pubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected pubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected pubA3_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected pubH3_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Publications") yscale(range(0 8)) ylabel(0(1)8) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Publications" "Math & Physical Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "MPS Awardee") label(4 "MPS Honorable Mention")) 
*graph save Graph "$dir/DD_CumPub3_`sample'.gph", replace	

* Social Sciences & Psychology  
twoway	(connected pubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected pubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected pubA4_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected pubH4_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Publications") yscale(range(0 8)) ylabel(0(1)8) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Publications" "Social Sciences & Psychology Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "SSP Awardee") label(4 "SSP Honorable Mention")) 
*graph save Graph "$dir/DD_CumPub4_`sample'.gph", replace	
}

** Annual Average 5-Year Citations for Cumulative Publications	
* By Award Status
foreach sample in cemsample {	
twoway	(connected citeA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected citeH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))), ///
	ytitle("Count of 5-Year Forward Citations") yscale(range(0 400)) ylabel(0(50)400) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Five-Year Forward Citation Count" " ", color(black) size(medsmall)) legend(label(1 "Awardee") label(2 "Honorable Mention")) 
*graph save Graph "$dir/DD_CumCite_`sample'.gph", replace

* By Division & Award Status 
* Enginnering 
twoway	(connected citeA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected citeH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected citeA1_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected citeH1_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Count of 5-Year Forward Citations") yscale(range(0 400)) ylabel(0(50)400) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Five-Year Forward Citation Count" "Engineering Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "ENG Awardee") label(4 "ENG Honorable Mention")) 
*graph save Graph "$dir/DD_CumCite1_`sample'.gph", replace	

* Life Sciences 
twoway	(connected citeA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected citeH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected citeA2_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected citeH2_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Count of 5-Year Forward Citations") yscale(range(0 400)) ylabel(0(50)400) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Five-Year Forward Citation Count" "Life Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "LS Awardee") label(4 "LS Honorable Mention")) 
*graph save Graph "$dir/DD_CumCite2_`sample'.gph", replace	

* Math & Physical Sciences 
twoway	(connected citeA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected citeH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected citeA3_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected citeH3_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Count of 5-Year Forward Citations") yscale(range(0 400)) ylabel(0(50)400) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Five-Year Forward Citation Count" "Math & Physical Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "MPS Awardee") label(4 "MPS Honorable Mention")) 
*graph save Graph "$dir/DD_CumCite3_`sample'.gph", replace	

* Social Sciences & Psychology  
twoway	(connected citeA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected citeH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected citeA4_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected citeH4_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Count of 5-Year Forward Citations") yscale(range(0 400)) ylabel(0(50)400) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Five-Year Forward Citation Count" "Social Sciences & Psychology Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "SSP Awardee") label(4 "SSP Honorable Mention")) 
*graph save Graph "$dir/DD_CumCite4_`sample'.gph", replace	
}

** Annual Average New Publications 	
* By Award Status
foreach sample in cemsample {	
twoway	(connected newpubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected newpubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))), ///
	ytitle("Number of New Publications") yscale(range(0 1.25)) ylabel(0(.25)1.25) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average New Publications" " ", color(black) size(medsmall)) legend(label(1 "Awardee") label(2 "Honorable Mention")) 
*graph save Graph "$dir/DD_NewPub_`sample'.gph", replace

* By Division & Award Status 
* Enginnering 
twoway	(connected newpubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected newpubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected newpubA1_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected newpubH1_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of New Publications") yscale(range(0 1.25)) ylabel(0(.25)1.25) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average New Publications" "Engineering Division", color(black)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "ENG Awardee") label(4 "ENG Honorable Mention") size(medsmall)) 
*graph save Graph "$dir/DD_NewPub1_`sample'.gph", replace	

* Life Sciences 
twoway	(connected newpubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected newpubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected newpubA2_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected newpubH2_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of New Publications") yscale(range(0 1.25)) ylabel(0(.25)1.25) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average New Publications" "Life Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "LS Awardee") label(4 "LS Honorable Mention")) 
*graph save Graph "$dir/DD_NewPub2_`sample'.gph", replace	

* Math & Physical Sciences 
twoway	(connected newpubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected newpubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected newpubA3_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected newpubH3_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of New Publications") yscale(range(0 1.25)) ylabel(0(.25)1.25) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average New Publications" "Math & Physical Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "MPS Awardee") label(4 "MPS Honorable Mention")) 
*graph save Graph "$dir/DD_NewPub3_`sample'.gph", replace	

* Social Sciences & Psychology  
twoway	(connected newpubA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected newpubH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected newpubA4_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected newpubH4_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of New Publications") yscale(range(0 1.25)) ylabel(0(.25)1.25) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average New Publications" "Social Sciences & Psychology Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "SSP Awardee") label(4 "SSP Honorable Mention")) 
*graph save Graph "$dir/DD_NewPub4_`sample'.gph", replace	
}

** Annual Average Cumulative Research Outputs 	
* By Award Status
foreach sample in cemsample {	
twoway	(connected resA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected resH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))), ///
	ytitle("Number of Total Research Outputs") yscale(range(0 10)) ylabel(0(2)10) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Research Outputs" " ", color(black) size(medsmall)) legend(label(1 "Awardee") label(2 "Honorable Mention")) 
*graph save Graph "$dir/DD_CumRes_`sample'.gph", replace

* By Division & Award Status 
* Enginnering 
twoway	(connected resA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected resH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected resA1_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected resH1_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Research Outputs") yscale(range(0 10)) ylabel(0(2)10) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Research Outputs" "Engineering Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "ENG Awardee") label(4 "ENG Honorable Mention")) 
*graph save Graph "$dir/DD_CumRes1_`sample'.gph", replace	

* Life Sciences 
twoway	(connected resA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected resH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected resA2_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected resH2_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Research Outputs") yscale(range(0 10)) ylabel(0(2)10) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Research Outputs" "Life Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "LS Awardee") label(4 "LS Honorable Mention")) 
*graph save Graph "$dir/DD_CumRes2_`sample'.gph", replace	

* Math & Physical Sciences 
twoway	(connected resA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected resH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected resA3_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected resH3_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Research Outputs") yscale(range(0 10)) ylabel(0(2)10) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Research Outputs" "Math & Physical Sciences Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "MPS Awardee") label(4 "MPS Honorable Mention")) 
*graph save Graph "$dir/DD_CumRes3_`sample'.gph", replace	

* Social Sciences & Psychology  
twoway	(connected resA_`sample' panel, mcolor(gold) lc(gold) msymbol(s)) ///
		(connected resH_`sample' panel, mcolor(black) lc(black) msymbol(o) xline(6, lpattern(longdash) lcolor(gs10))) ///
		(connected resA4_`sample' panel, mcolor(teal) lc(teal) msymbol(t)) ///
		(connected resH4_`sample' panel, mcolor(navy) lc(navy) msymbol(x)), ///
	ytitle("Number of Total Research Outputs") yscale(range(0 10)) ylabel(0(2)10) xtitle("Year") xlabel(1 "-5" 6 "0" 11 "5" 16 "10") ///
	graphregion(fcolor(white)) title("Annual Average Cumulative Research Outputs" "Social Sciences & Psychology Division", color(black) size(medsmall)) ///
	legend(label(1 "Awardee") label(2 "Honorable Mention") label(3 "SSP Awardee") label(4 "SSP Honorable Mention")) 
*graph save Graph "$dir/DD_CumRes4_`sample'.gph", replace	
}

********************************************************************************
				*** Up Next: Part 3 - Analysis ***
********************************************************************************
